﻿
Partial Public Class MainPage
    Private Shared Function slider_mode(ByVal width As Double, ByVal height As Double) As Boolean
        Return width < height
    End Function

    Private Function slider_mode() As Boolean
        Return slider_mode(Me.Width(), Me.Height())
    End Function

    Private Sub resize(ByVal width As Double, ByVal height As Double)
        right.Height() = height
        media.Height() = height
        If slider_mode(width, height) Then
            right.Width() = width
            media.Visibility() = False
        Else
            right.Width() = (width >> 2)
            media.Width() = width - right.Width()
            media.Visibility() = True
        End If
    End Sub

    Private Sub right_SizeChanged(sender As Object, e As SizeChangedEventArgs) Handles right.SizeChanged
        For Each i In right.Children()
            i.as(Of FrameworkElement)().Width() = right.ActualWidth()
        Next
        right_inner.Height() = right.ActualHeight()
    End Sub

    Private Sub MainPage_SizeChanged(sender As Object, e As SizeChangedEventArgs) Handles Me.SizeChanged
        resize(e.NewSize().Width(), e.NewSize().Height())
    End Sub

    Private Sub add_buttons_SizeChanged(sender As Object, e As SizeChangedEventArgs) Handles add_buttons.SizeChanged
        Dim but_width As Double = 0
        but_width = add_buttons.ActualWidth() / add_buttons.Children().Count()
        For Each i In add_buttons.Children()
            Dim b As Button = Nothing
            b = DirectCast(i, Button)
            If Not b Is Nothing Then
                b.Width() = but_width
            End If
        Next
    End Sub

    Private Sub right_inner_SizeChanged(sender As Object, e As SizeChangedEventArgs) Handles right_inner.SizeChanged
        For Each i In right_inner.Children()
            i.as(Of FrameworkElement)().Width() = right_inner.ActualWidth()
        Next
        list.Height() = right_inner.ActualHeight() - add_buttons.Height()
    End Sub
End Class
